#include "barcodescanner.h"

#include <QDebug>
#include <QFile>
#include <QPainter>
#include <QProcess>
#include <QUrl>

BarcodeScanner::BarcodeScanner()
{
    resourcePath = QDir(QDir::currentPath().append("/../Resources/barcodeScanner/"));
}

QString BarcodeScanner::recognize() {
    QProcess script(this);
    script.setWorkingDirectory(resourcePath.absolutePath());
    script.start("./barcode.bash");
    script.waitForFinished();

    QFile file(resourcePath.absoluteFilePath("barcode.txt"));
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return "";

    QTextStream in(&file);
    while (!in.atEnd()) {
        QString barcode = in.readLine();
        return barcode;
    }
    return "";
}
